# -*- coding: utf-8 -*- 
# @Time : 2023/6/24 9:21 
# @Author : gkm
# @File : setting.py
from django.shortcuts import render, HttpResponse, redirect
from web import models

def setting(request, project_id):
    return render(request, 'setting.html')


def delete(request, project_id):
    '''删除项目'''
    if request.method == 'GET':
        return render(request, 'setting_delete.html')
    project_name = request.POST.get('project_name')
    if not project_name or project_name != request.tracer.project.name:
        return render(request, 'setting_delete.html', {'error': '项目名输入错误'})

    if request.tracer.user != request.tracer.project.creator:
        return render(request, 'setting_delete.html', {'error': '该用户没有权限删除'})

    # 删除COS桶
    #           -删除桶中的文件；
    #           -删除桶中的碎片；
    #        -删除桶
    # 删除项目
    delete_bucket(request.tracer.project.bucket, request.tracer.project.region)
    models.FileRepository.objects.filter(id=request.tracer.project.id).delete()

    return redirect('project_list')